﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Ppt = Microsoft.Office.Interop.PowerPoint;

namespace ObjectModel.PowerPoint
{
    /// <summary>
    /// A PowerPoint shape object that can resolve itself from serializable info.
    /// </summary>
    public class ResolvableShape : ResolvableObject
    {
        public ResolvableSlide Slide { get; set; }

        public int Id { get; set; }

        public string Name { get; set; }

        public ResolvableShape() { } // Parameterless constructor required for deserialization.

        public ResolvableShape(Ppt.Shape shape)
        {
            Slide = new ResolvableSlide(shape.GetParent<Ppt.Slide>());
            Id = shape.Id;
            Name = shape.Name;
        }

        public override object Resolve()
        {
            Ppt.Slide slide = Slide.Resolve() as Ppt.Slide;
            return slide.Shapes.FindById(Id);
        }

        [XmlIgnore]
        public bool Selected
        {
            get
            {
                Ppt.Selection sel = Globals.Application.ActiveWindow.Selection;

                if (sel.SlideRange.Count > 0 && sel.SlideRange[1].SlideID == Slide.Id)
                    foreach (Ppt.Shape sh in sel.ShapeRange)
                        if (sh.Id == Id)
                            return true;

                return false;
            }
        }
    }
}
